package com.loit.loitcommon.utils;

import sun.misc.BASE64Decoder;

import java.io.FileOutputStream;

/**
 * 二进制转图片文件
 */
public class decoderdStringToPDF {
	public static void main(String[] args) throws Exception {
		// 首先对报文进行拆解，获取报文中的jkewmwj内容
		String fileContent = "iVBORw0KGgoAAAANSUhEUgAAAGcAAABnCAIAAACSI8uuAAACIklEQVR42u3aS27DMAxFUe9/08mws8TiuxSV+mqYArZ0jBL86Hq51tclQV3tytbf41Z++fCcTzsuvfTO2++fVDXVptTW/r2zzW2AWNrz/ZOqptq4Wnja2gHCY/ftWTXVnqO29Cc8Gqqmmmo3g04t0i3tJ3yFaqodqxbWBktRjOKrqR1UUamm2je1nf212V9+tSup2iPVGsc5pZPUwmLYWz9osqeaauvzUEokTBTwhAOoDVRTrVmtJoJHMbwgCV+6nHmoplqzGvLQPcU21WgD4ppqqjWr9Y1va58hdOxr86mm2ogaPiWiqm58RoUkQKqpNqVWe+iGJhrVX0AG3qqpNqVGXd0IL4VQlXlT0aKaapvVqPNv6KTXWtjs51RNtSk1qjLv3nfe5ks+uWqqjavhRXKtGY2PgZG+gGqqTanheXbTlKgc15Dwqppqm9WoFbbLl7p71J2SQgNRNdXG1ahIN5Jw9E2jVVPtNLWwIK+1ucPTdt9WUU21zWq13lmYOvSNr6jjqKbaaWrUDQl2apt/BqqeV021ETV8fFujCQ/Zt8Mv+Zpqqu1SG+mv4ZOkvoipmmojale2+u55UBPi2rtUU+00NarVxcaRclKCD7NVU+0QNWqAFKbytY+HZzCqqfY/1KjrHRsGWslzVFPt19XCES8+4grD9Ka4pppqzXVoKBt2Aah6vh7XVFOtWa0vqx7piVMb6+1Kqqba+r1c177J3kPWG8HdmepZp7IjAAAAAElFTkSuQmCC";
// 从webservice接口获取二维码字符串
		String targetPath = "d:/123.png";
		decoderdBase64File(fileContent, targetPath);
	}

	/**
	 * 将一个二维码字符串进行Base64解码，并写入路径
	 * 
	 * @param base64Code
	 * @param targetPath
	 * @throws Exception
	 */
	public static void decoderdBase64File(String base64Code, String targetPath) throws Exception {
		byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);
		FileOutputStream out = new FileOutputStream(targetPath);
		out.write(buffer);
		out.close();
	}
}